package com.bringway.global.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

public class GlobalUtils {

	 /**
     * 获取登录IP地址
     * @author xuef
     * @date 2017年5月15日10:15:13
     */
    public static String getRemoteAddr(HttpServletRequest request)
	{
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
		{
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
		{
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
		{
			ip = request.getRemoteAddr();
		}
		return ip;
	}
    
    
    public static Map<String, String> getQuestParamMap(HttpServletRequest request){
    	Enumeration<String> reqParamNames = request.getParameterNames();
		Map<String, String> reqParams = new HashMap<String, String>();
		while (reqParamNames.hasMoreElements()) {
			String paramName = (String) reqParamNames.nextElement();
			String[] paramValues = request.getParameterValues(paramName);
			if (paramValues.length == 1) {
				String paramValue = paramValues[0];
				if (paramValue.length() != 0) {
					reqParams.put(paramName, paramValue);
				}
			}
		}
		return reqParams;
    }
    
    
    
}
